package com.delu.controller;

import com.delu.data.Result;
import com.delu.em.ResultEnum;
import com.delu.entity.CarSpecification;
import com.delu.mapper.CarSpecificationsMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("carSpecification")
@Api("汽车信息")
public class CarSpecificationController {
    @Resource
    private CarSpecificationsMapper carSpecificationsMapper;

    @GetMapping
    @ApiOperation("汽车信息管理查询")
    @ApiImplicitParam(name = "carSpecid",value = "信息ID",required = true,paramType = "query")
    public Result selectCarSpecification(@RequestParam("carSpecid")Long carSpecid){
        System.out.println("汽车信息管理查询" + carSpecid);
        List<CarSpecification> carSpecificationList = carSpecificationsMapper.selectCarSpecification(carSpecid);
        return Result.response(ResultEnum.SUCCESS).setData(carSpecificationList);
    }

    @PostMapping
    @ApiOperation("汽车信息管理增加")
    @ApiImplicitParam(name = "CarSpecification",value = "信息实体类",required = true,paramType = "body")
    public Result insertCarSpecification(@RequestBody CarSpecification carSpecification){
        Integer i = carSpecificationsMapper.insert(carSpecification);
        System.out.println("汽车信息" + carSpecification);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

    @PutMapping
    @ApiOperation("汽车信息管理修改")
    @ApiImplicitParam(name = "CarSpecification",value = "信息实体类",required = true,paramType = "body")
    public Result updateCarSpecification(@RequestBody CarSpecification carSpecification){
        Integer i = carSpecificationsMapper.updateById(carSpecification);
        System.out.println("汽车信息" + carSpecification);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

    @DeleteMapping
    @ApiOperation("汽车信息管理删除")
    @ApiImplicitParam(name = "carSpecid",value = "信息ID",required = true,paramType = "query")
    public Result deleteCarSpecification(@RequestParam("carSpecid")Long carSpecid){
        Integer i = carSpecificationsMapper.deleteById(carSpecid);
        System.out.println("汽车信息" + carSpecid);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }
}
